import 'package:boss/color_constant.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/widget/timeRangePicker/provider/time_range_picker_provider.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class TimeRangePickerItem extends StatelessWidget {
  final String time;
  final int index;
  final VoidCallback onTap;

  const TimeRangePickerItem({
    this.time,
    this.index,
    this.onTap,
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Consumer<TimeRangePickerProvider>(
      builder: (context, provider, child) {
        bool isStartTime = provider.startTime == index;
        bool isEndTime = provider.endTime == index;
        bool isSelectedStarEnd = provider.startTime != null && provider.endTime != null;
        bool isBetween = isSelectedStarEnd ? index > provider.startTime && index < provider.endTime : false;

        double radius = 66.w;

        return GestureDetector(
          onTap: onTap,
          child: Container(
              width: 100.w,
              height: 66.w,
              decoration: BoxDecoration(
                color: isStartTime || isEndTime ? ColorConstant.ff5770f6 : Colors.transparent,
                borderRadius: BorderRadius.circular(radius),
              ),
              alignment: Alignment.center,
              child: Text(
                '$time',
                style: isBetween || isStartTime || isEndTime ? TextStyleConstant().white_28 : TextStyleConstant().normal_1_28,
              )),
        );
      },
    );
  }
}